package com.ce.cases.assit.logic.search;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import com.ce.cases.assit.view.CaseEntrustCheckView;
import com.ce.framework.datamaintain.logic.ISQLMapper;
import com.ce.framework.datamaintain.logic.SQLSearchCondition;
import com.ce.framework.exception.AppException;
import com.ce.framework.util.DateUtil;
import com.ce.framework.util.StringUtil;

/**
* 嫦娥软件有限公司 版权所有 2013
* 创建人：　andy
* 创建日期：2014-04-11
* 创建时间：14:16:26
* 功能描述：委托协查台账 [CASE_ENTRUST_CHECK]条件过滤类
* ==============================================
* 修改历史
* 修改人		修改时间		修改原因
*
* ==============================================
*/
public class CaseEntrustCheckSearchCondition  extends SQLSearchCondition
	implements ISQLMapper
{
	private String assitType;
	private String entrstCode;
	private String entrstDept;
	private String collectDept;
	private String enterpriceName;
	private String regBeginDate;
	private String regEndDate;
	
	@Override
	public String getExcelName() {
		return "委托协查管理台帐_"+DateUtil.format(new Date(),"yyyyMMddHHmm");
	}
	public String getSearchSql() throws AppException {
		
		StringBuffer sql = new StringBuffer("select * from CASE_ENTRUST_CHECK t where t.VC_DEL$FLAG = 0");
		if(StringUtil.isNotBlank(assitType)){
			sql.append(" and t.assit_type_num=${assitType}");
		}
		if(StringUtil.isNotBlank(entrstCode)){
			sql.append(" and t.entrust_code like '%'||${entrstCode}||'%'");
		}
		if(StringUtil.isNotBlank(entrstDept)){
			sql.append(" and t.entrust_dept_id=${entrstDept}");
		}
		if(StringUtil.isNotBlank(collectDept)){
			sql.append(" and t.collection_dept_id=${collectDept}");
		}
		if(StringUtil.isNotBlank(enterpriceName)){
			sql.append(" and t.involved_enterprice like '%'||${enterpriceName}||'%'");
		}
		/*
		 * 2015-06-09 by 刘渝洪，开始 
		 * 修改搜索处理
		 * 默认初始列表时，或搜索日期条件没值时，搜索出的结果为：本年度的数据
		 * 设置搜索日期条件时，搜索出的结果为：满足日期条件的数据
		 * 原代码：
		 * sql.append(this.getDateCondition("register_date", regBeginDate, regEndDate));
		 * 修改后代码：
		 */
		if (StringUtil.isNotBlank(regBeginDate)
				|| StringUtil.isNotBlank(regEndDate)) {
			sql.append(this.getDateCondition("register_date", regBeginDate, regEndDate));
		} else {
			String dateBeginOfThisYear = DateUtil.getYear() + "-01-01 00:00:00";
			String dateEndOfThisYear = DateUtil.getYear() + "-12-31 23:59:59";
			sql.append(" and ").append("register_date").append(">=to_date('")
					.append(dateBeginOfThisYear)
					.append("','yyyy-mm-dd hh24:mi:ss') ");
			sql.append(" and ").append("register_date").append("<=to_date('")
					.append(dateEndOfThisYear)
					.append("','yyyy-mm-dd hh24:mi:ss') ");
		}
		/* 2015-06-09 by 刘渝洪，结束 */
		//排序
		if(StringUtil.isNotBlank(this.order)){
            sql.append(" order by "+ this.getOrderByUnderLine());
		}else{
			 sql.append(" order by register_date desc");
		}
		return sql.toString();
	}
	
	public Object fromSQLQuery(ResultSet rs, int num) {
		CaseEntrustCheckView view = new CaseEntrustCheckView();
		try {
			view.setVcId(rs.getString("VC_ID"));
			view.setAssitTypeNum(rs.getString("ASSIT_TYPE_NUM"));
			view.setAssitTypeName(rs.getString("ASSIT_TYPE_NAME"));
			view.setEntrustCode(rs.getString("ENTRUST_CODE"));
			view.setIsCity(rs.getInt("IS_CITY"));
			view.setStartDept(rs.getString("START_DEPT"));
			view.setAssitTax(rs.getString("ASSIT_TAX"));
			view.setTaxpayerNumber(rs.getString("TAXPAYER_NUMBER"));
			view.setInvolvedEnterprice(rs.getString("INVOLVED_ENTERPRICE"));
			view.setEntrustDeptId(rs.getString("ENTRUST_DEPT_ID"));
			view.setEntrustDept(rs.getString("ENTRUST_DEPT"));
			view.setCollectionDeptId(rs.getString("COLLECTION_DEPT_ID"));
			view.setCollectionDept(rs.getString("COLLECTION_DEPT"));
			view.setBillCount(rs.getInt("BILL_COUNT"));
			view.setAmountMoney(rs.getDouble("AMOUNT_MONEY"));
			view.setTaxMoney(rs.getDouble("TAX_MONEY"));
			view.setAssitReason(rs.getString("ASSIT_REASON"));
			view.setReplyLimitDate(rs.getDate("REPLY_LIMIT_DATE"));
			view.setReplyDate(rs.getDate("REPLY_DATE"));
			view.setReplyCode(rs.getString("REPLY_CODE"));
			view.setOntimeReply(rs.getInt("ONTIME_REPLY"));
			view.setTotalBill(rs.getInt("TOTAL_BILL"));
			view.setProblemBill(rs.getInt("PROBLEM_BILL"));
			view.setNoVerify(rs.getInt("NO_VERIFY"));
			view.setIsNormal(rs.getInt("IS_NORMAL"));
			view.setReplyPerson(rs.getString("REPLY_PERSON"));
			view.setCheckCounts(rs.getDouble("CHECK_COUNTS"));
			view.setCheckTax(rs.getDouble("CHECK_TAX"));
			view.setCheckFine(rs.getDouble("CHECK_FINE"));
			view.setCheckLatefees(rs.getDouble("CHECK_LATEFEES"));
			view.setInCounts(rs.getDouble("IN_COUNTS"));
			view.setInTax(rs.getDouble("IN_TAX"));
			view.setInFine(rs.getDouble("IN_FINE"));
			view.setInLatefees(rs.getDouble("IN_LATEFEES"));
			view.setPassJudiciary(rs.getInt("PASS_JUDICIARY"));
			view.setInRegisterPerson(rs.getString("IN_REGISTER_PERSON"));
			view.setInRegisterDate(rs.getDate("IN_REGISTER_DATE"));
			view.setRegisterPerson(rs.getString("REGISTER_PERSON"));
			view.setRegisterDeptId(rs.getString("REGISTER_DEPT_ID"));
			view.setRegisterDate(rs.getDate("REGISTER_DATE"));
			view.setVcDelFlag(rs.getInt("VC_DEL$FLAG"));			

		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return view;
	}
	
	public ISQLMapper getSQLMapper() {
		
		return this;
	}

	public String getAssitType() {
		return assitType;
	}

	public void setAssitType(String assitType) {
		this.assitType = assitType;
	}

	public String getEntrstCode() {
		return entrstCode;
	}

	public void setEntrstCode(String entrstCode) {
		this.entrstCode = entrstCode;
	}

	public String getEntrstDept() {
		return entrstDept;
	}

	public void setEntrstDept(String entrstDept) {
		this.entrstDept = entrstDept;
	}

	public String getCollectDept() {
		return collectDept;
	}

	public void setCollectDept(String collectDept) {
		this.collectDept = collectDept;
	}

	public String getEnterpriceName() {
		return enterpriceName;
	}

	public void setEnterpriceName(String enterpriceName) {
		this.enterpriceName = enterpriceName;
	}

	public String getRegBeginDate() {
		return regBeginDate;
	}

	public void setRegBeginDate(String regBeginDate) {
		this.regBeginDate = regBeginDate;
	}

	public String getRegEndDate() {
		return regEndDate;
	}

	public void setRegEndDate(String regEndDate) {
		this.regEndDate = regEndDate;
	}
	
	

}

